﻿@{
    ViewBag.Title = "投诉管理";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}

<script>
    var _state = "", _psallname="";
    var _organizeid = "@LeSoft.Application.Code.OperatorProvider.Provider.Current().CompanyId";
    $(function () {
        InitialPage();
        GetTree1();
        GetTree2();
        GetGrid();
    });
    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width()));
                $("#gridTable").setGridHeight($(window).height() - 168.5);
                //$("#itemTree").setTreeHeight($(window).height() - 52);
            }, 200);
            e.stopPropagation();
        });
        //绑定组织机构
        $("#Organize").ComboBoxTree({
            url: "../../BaseManage/Organize/GetTreeJsonById",
            height: "250px",
            click: function (item) {
                if (_organizeid != item.id) {
                    _organizeid = item.id;
                    GetTree2();
                    _psallname = item.text;
                    SearchEvent();
                }
            }
        });
        $("#Organize").ComboBoxTreeSetValue(_organizeid);

        //投诉方式
        $("#ComplaintWay").ComboBoxTree({
            url: "../../SystemManage/DataItemDetail/GetDataItemTreeJson",
            param: { EnCode: "ComplainWay" },
            description: "==请选择==",
            height: "200px"
        });
        //投诉类别
        $("#ComplaintType").ComboBoxTree({
            url: "../../SystemManage/DataItemDetail/GetDataItemTreeJson",
            param: { EnCode: "ComplatinType" },
            description: "==请选择==",
            height: "200px"
        });
        //时间
        $("#time_horizon").ComboBox({
            data: [{ "key": 2, "value": "上周" }, { "key": 1, "value": "本周" }, { "key": 4, "value": "上月" }, { "key": 3, "value": "本月" }, { "key": 5, "value": "本年" }],
            id: "key",
            text: "value",
            //description: "==请选择==",
            click: function (item) {
                var value = item.attr('data-value');
                switch (value) {
                    case "1"://本周
                        $("#StartTime").val("@DateTime.Now.AddDays(1 - DateTime.Now.DayOfWeek.GetHashCode()).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(7 - DateTime.Now.DayOfWeek.GetHashCode()).ToString("yyyy-MM-dd")");
                        break;
                    case "2"://上周
                        $("#StartTime").val("@DateTime.Now.AddDays(1 - DateTime.Now.DayOfWeek.GetHashCode()-7).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(7 - DateTime.Now.DayOfWeek.GetHashCode()-7).ToString("yyyy-MM-dd")");
                        break;
                    case "3"://本月
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day+1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddMonths(1).AddDays(- DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    case "4"://上月
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day + 1).AddMonths(-1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    case "5"://本年
                        $("#StartTime").val("@DateTime.Now.AddDays(-DateTime.Now.DayOfYear + 1).ToString("yyyy-MM-dd")");
                        $("#EndTime").val("@DateTime.Now.AddMonths(12 - DateTime.Now.Month + 1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")");
                        break;
                    default:
                        break;
                }
                $("#SelectedStartTime").html($("#StartTime").val());
                $("#SelectedEndTime").html($("#EndTime").val());
                SearchEvent();
            }
        });
        $("#time_horizon").ComboBoxSetValue(3);
        
    }

    //加载树
    function GetTree1() {
        var queryJson = $("#filter-form").GetWebControls();
        //queryJson["State"] = _state;
        queryJson["PSAllName"] = _psallname;
        queryJson["OrganizeId"] = _organizeid;
        queryJson["ComplaintType"] = $('#ComplaintType').attr('data-value');
        queryJson["ComplaintWay"] = $('#ComplaintWay').attr('data-value');
        var item = {
            url: "../../PropertyManage/CS_Complaints/GetStateTreeList?queryJson=" + JSON.stringify(queryJson),
            onnodeclick: function (item) {
                _state = item.id;
                SearchEvent();
            }
        };
        //初始化
        $("#itemTree1").treeview(item);
    }
    function GetTree2() {
        var item = {
            url: "../../ResourceManage/RS_PStructs/GetTreeJson?IsSubstep=true&type=5&organizeid=" + _organizeid,
            onnodeclick: function (item) {
                _psallname = item.text;
                SearchEvent();
            }
        };
        //初始化
        $("#itemTree2").treeview(item);
    }
    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var queryJson = $("#filter-form").GetWebControls();
        queryJson["State"] = _state;
        queryJson["PSAllName"] = _psallname;
        queryJson["OrganizeId"] = _organizeid;

        var $gridTable = $('#gridTable');       
        $gridTable.jqGrid({
            url: "../../PropertyManage/CS_Complaints/GetPageListJson",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 168.5,
            autowidth: true,
            colModel: [
                  { label: "主键", name: "Id", index: "Id", hidden: true },
                  { label: "单据编号", name: "Code", index: "Code", width: 150, align: "left" },
                  { label: "单据日期", name: "Date", index: "Date", width: 150, align: "left" },
                  {
                      label: "单据来源", name: "SourceType", index: "SourceType", width: 120, align: "center",
                      formatter: function (cellvalue, options, rowObject) {
                          switch (cellvalue) {
                              case 0: return "内部协调"; break;
                              case 1: return "APP"; break;
                              case 2: return "微信"; break;
                              case 3: return "Web转单"; break;
                              case 4: return "App转单"; break;
                              case 5: return ""; break;
                              default: return "内部协调"; break;
                          }
                      }
                  },
                  {
                      label: "处理状态", name: "State", index: "State", width: 150, align: "left",
                      formatter: function (cellvalue, options, rowObject) {
                          switch (cellvalue) {
                              case 1: return "<span class=\"label label-success\">未处理</span>"; break;
                              case 2: return "<span class=\"label label-primary\">受理中</span>"; break;
                              case 3: return "<span class=\"label label-success\">未派单</span>"; break;
                              case 4: return "<span class=\"label label-danger\">派单中</span>"; break;                           
                              case 5: return "<span class=\"label label-danger\">处理中</span>"; break;                             
                              case 6: return "<span class=\"label label-primary\">已处理，未回访</span>"; break;
                              case 7: return "<span class=\"label label-primary\">已处理，已回访</span>"; break;
                              case 8: return "<span class=\"label label-danger\">已取消</span>"; break;
                              default: return ""; break;
                          }
                      }
                  },
                  {
                     label: "投诉类别", name: "ComplaintType", index: "ComplaintType", width: 150, align: "left",
                    formatter: function (cellvalue, options, rowObject) {
                        
                        return cellvalue == null ? "" : top.clientdataItem["ComplainType"][cellvalue];
                    }
                  },
                   {
                       label: "投诉方式", name: "ComplaintWay", index: "ComplaintWay", width: 150, align: "left",
                       formatter: function (cellvalue, options, rowObject) {
                           return cellvalue == null ? "" : top.clientdataItem["ComplainWay"][cellvalue];
                       }
                   },
                { label: "投诉人房屋", name: "Location", index: "Location", width: 150, align: "left" },
                { label: "投诉人", name: "ComplaintMan", index: "ComplainantMan", width: 150, align: "left" },
                { label: "投诉人电话", name: "ComplaintPhone", index: "ComplainantPhone", width: 150, align: "left" },              
                { label: "投诉内容", name: "ComplaintContent", index: "ComplainantContent", width: 150, align: "left" } 
            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100, 500, 1000],
            pager: "#pager",
            sortname: 'Date desc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
        //查询事件
        $("#btn_Search").click(function () {
            SearchEvent();
            $(".ui-filter-text").trigger("click");
            $("#SelectedStartTime").html($("#StartTime").val());
            $("#SelectedEndTime").html($("#EndTime").val());
        });
    }

    //查询表格函数
    function SearchEvent() {
        var queryJson = $("#filter-form").GetWebControls();
        queryJson["State"] = _state;
        queryJson["PSAllName"] = _psallname;
        queryJson["OrganizeId"] = _organizeid;
        queryJson["ComplaintType"] = $('#ComplaintType').attr('data-value');
        queryJson["ComplaintWay"] = $('#ComplaintWay').attr('data-value');
        $("#gridTable").jqGrid('setGridParam', {
            url: "../../PropertyManage/CS_Complaints/GetPageListJson",
            postData: { queryJson: JSON.stringify(queryJson) },
            page: 1
        }).trigger('reloadGrid');
        GetTree1();
    }
    //新增
    function btn_add() {
        dialogOpen({
            id: "Form",
            title: '添加投诉',
            url: '/PropertyManage/CS_Complaints/Form',
            width: "1100px",
            height: "850px",           
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    }
    //编辑
    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "Form",
                title: '编辑投诉单',
                url: '/PropertyManage/CS_Complaints/Form?keyValue=' + keyValue,
                width: "1100px",
                height: "850px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            });
        }
    }

    //删除
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (keyValue) {
            $.RemoveForm({
                url: "../../PropertyManage/CS_Complaints/RemoveForm",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择需要删除的业务！', 0);
        }
    }
</script>

<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel" style="height: 35%; overflow-y: auto; ">
            <div id="itemTree1"></div>
        </div>
        <div class="west-Panel" style="height: 61.5%; overflow-y: auto;">
            <div id="Organize" type="select" class="ui-select"></div>
            <div id="itemTree2"></div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div class="panel-Title">投诉管理</div>
            <div class="titlePanel">
                <div class="title-search">
                    <table>
                        <tr>
                            <td>查询条件</td>
                            <td style="padding-left: 10px;">
                                <div class="ui-filter" style="width: 200px;">
                                    <div class="ui-filter-text">
                                        <strong id="SelectedStartTime">@DateTime.Now.AddDays(-DateTime.Now.Day + 1).ToString("yyyy-MM-dd")</strong> 至 <strong id="SelectedEndTime">@DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")</strong>
                                    </div>
                                    <div class="ui-filter-list" style="width: 350px;">
                                        <table class="form" id="filter-form">
                                            <tr>
                                                <th class="formTitle">单据时间：</th>
                                                <td class="formValue">
                                                    <div style="float: left; width: 45%;">
                                                        <input id="StartTime" readonly type="text" value="@DateTime.Now.AddDays(-DateTime.Now.Day + 1).ToString("yyyy-MM-dd")" class="form-control input-wdatepicker" onfocus="WdatePicker()">
                                                    </div>
                                                    <div style="float: left; width: 10%; text-align: center;">至</div>
                                                    <div style="float: left; width: 45%;">
                                                        <input id="EndTime" readonly type="text" value="@DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day).ToString("yyyy-MM-dd")" class="form-control input-wdatepicker" onfocus="WdatePicker()">
                                                    </div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">单据编号：</td>
                                                <td class="formValue">
                                                    <input id="Code" type="text" class="form-control">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">投诉类型</td>
                                                <td class="formValue">
                                                    <div id="ComplaintType" type="select" class="ui-select"></div>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td class="formTitle">投诉方式</td>
                                                <td class="formValue">
                                                    <div id="ComplaintWay" type="select" class="ui-select"></div>
                                                </td>
                                            </tr>
                                        </table>
                                        <div class="ui-filter-list-bottom">
                                            <a id="btn_Reset" class="btn btn-default">&nbsp;重&nbsp;&nbsp;置</a>
                                            <a id="btn_Search" class="btn btn-primary">&nbsp;查&nbsp;&nbsp;询</a>
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td style="padding-left: 10px;">
                                <div id="time_horizon" type="selectTree" class="ui-select" style="width: 60px;"></div>
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="toolbar">
                    <div class="btn-group">
                        <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        <a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新    增</a>
                        <a id="lr-edit" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                        <a id="lr-delete" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                    </div>
                    <script>$('.toolbar').authorizeButton()</script>
                </div>
            </div>
            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="pager" class="scroll"></div>
            </div>
        </div>
    </div>
</div>
